package org.example.sunrise.views;

import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.scene.control.Button;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.AnchorPane;
import org.example.sunrise.core.Context;
import org.example.sunrise.core.ViewEnum;
import org.example.sunrise.utils.ButtonUtil;

import java.util.Objects;

public class SimpleQuitView extends AnchorPane {
    private final Context ctx;

    public SimpleQuitView(Context ctx) {
        this.ctx = ctx;
        createView();
    }

    private void createView() {
        ImageView imageView = new ImageView();
        imageView.setImage(new Image(Objects.requireNonNull(SimpleMenuView.class.getResource("defaultQuit/quitScreen.png")).toString()));
        this.getChildren().addAll(imageView, createCancel(), createQuit());
    }

    private Button createQuit() {
        Button quit = ButtonUtil.createMenuTransparentButton(230, 375, 147, 42);
        quit.setOnAction(this::quit);
        ButtonUtil.setHandCursor(quit, ctx.sunriseFactory()::getScene);
        return quit;
    }

    private Button createCancel() {
        Button cancel = ButtonUtil.createMenuTransparentButton(400, 375, 153, 35);
        cancel.setOnAction(this::cancel);
        ButtonUtil.setHandCursor(cancel, ctx.sunriseFactory()::getScene);
        return cancel;
    }

    private void quit(ActionEvent evt) {
        Platform.exit();
    }

    private void cancel(ActionEvent evt) {
        ctx.sunriseFactory().show(ViewEnum.MAIN);
    }
}
